import { ref } from "vue";

const drawerOpened = ref(fetchDrawerOpened());

function fetchDrawerOpened() {
  const storaged = localStorage.getItem("drawerOpened");
  if (storaged == null) {
    return true;
  }
  return storaged != "false";
}

function updateDrawer(opened) {
  drawerOpened.value = opened;
  localStorage.setItem("drawerOpened", opened);
}

function toggleDrawer() {
  updateDrawer(!fetchDrawerOpened());
}

export { fetchDrawerOpened, updateDrawer, toggleDrawer, drawerOpened };